/*    */ package com.hs.activation.common.utils;
/*    */ 
/*    */ import java.util.regex.Matcher;
/*    */ import java.util.regex.Pattern;
/*    */ import javax.mail.MessagingException;
/*    */ import javax.mail.internet.MimeMessage;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.beans.factory.annotation.Value;
/*    */ import org.springframework.mail.javamail.JavaMailSender;
/*    */ import org.springframework.mail.javamail.MimeMessageHelper;
/*    */ import org.springframework.scheduling.annotation.Async;
/*    */ import org.springframework.stereotype.Component;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ @Component
/*    */ public class MailUtil
/*    */ {
/*    */   @Autowired
/*    */   JavaMailSender mailSender;
/*    */   @Value("${spring.mail.username}")
/*    */   private String userName;
/*    */   
/*    */   @Async("taskExecutor")
/*    */   public void sendMail(String toMail, String title, String text) {
/* 41 */     if (!checkEmail(toMail)) {
/*    */       return;
/*    */     }
/*    */     
/* 45 */     MimeMessage mimeMessage = this.mailSender.createMimeMessage();
/*    */     
/*    */     try {
/* 48 */       MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
/* 49 */       helper.setFrom(this.userName);
/* 50 */       helper.setTo(toMail);
/* 51 */       helper.setSubject(title);
/* 52 */       mimeMessage.setContent("<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Document</title>\n</head>\n<body>\n" + text + "    \n</body>\n</html>", "text/html ;charset=gbk");
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */       
/* 66 */       this.mailSender.send(mimeMessage);
/* 67 */     } catch (MessagingException e1) {
/*    */       
/* 69 */       e1.printStackTrace();
/*    */     } 
/*    */   }
/*    */   
/*    */   public static boolean checkEmail(String email) {
/* 74 */     boolean flag = false;
/*    */     try {
/* 76 */       String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
/* 77 */       Pattern regex = Pattern.compile(check);
/* 78 */       Matcher matcher = regex.matcher(email);
/* 79 */       flag = matcher.matches();
/* 80 */     } catch (Exception e) {
/* 81 */       flag = false;
/*    */     } 
/* 83 */     return flag;
/*    */   }
/*    */ }


/* Location:              C:\Users\yzc\Desktop\新建文件夹 (3)\activation-0.0.16.jar!\BOOT-INF\classes\com\hs\activation\commo\\utils\MailUtil.class
 * Java compiler version: 16 (60.0)
 * JD-Core Version:       1.1.3
 */